package com.imooc.miaosha.service.impl;

import com.imooc.miaosha.dao.ShippingMapper;
import com.imooc.miaosha.pojo.Shipping;
import com.imooc.miaosha.service.ShippingService;
import com.imooc.miaosha.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShippingServiceImpl implements ShippingService {
    @Autowired
    ShippingMapper shippingMapper;

    @Override
    public List<Shipping> shippingList(Long userId) {
        List<Shipping> shippingList = shippingMapper.listShippingByUserId(userId);

        return shippingList;
    }

    @Override
    public List<Shipping> add(Shipping shipping, Long userId) {
        shipping.setUserId(userId);

        shippingMapper.insertSelective(shipping);
        return this.shippingList(userId);
    }

    @Override
    public List<Shipping> del(Long userId, Long shippingId) {
        shippingMapper.deleteShippingByUserIdAndShippingId(shippingId, userId);
        return shippingList(userId);
    }

    @Override
    public boolean isUserShpping(Long shippingId, Long userId) {
        return shippingMapper.countShippingAndUserId(userId, shippingId) > 0;
    }
}
